/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package biofilter.factories;

import biofilter.records.BlastTabRecord;
import biofilter.records.BowTieRecord;
import biofilter.records.GFFRecord;
import biofilter.records.Mapper454Record;
import biofilter.records.Record;
import biofilter.util.MappedPosition;

/**
 * The MappedPositionFactory creates an object that implements the MappedPosition
 * Interface.
 * @author Daniel Quest
 * @date   Feb 23rd 2010
 */
public class MappedPositionFactory {

    public MappedPositionFactory() {

    }

    public MappedPositionFactory(String mappedPositionType) {
        this.mappedPositionType = mappedPositionType;
    }



    public GFFRecord GFFconverter(Record r){
        //System.err.println("MappedPositionFactory 34: " + this.mappedPositionType);
        MappedPosition mp = (MappedPosition) this.getMappedRecord(this.mappedPositionType, r.get());
        //note that we have to loose information here because not every mapped position
        //type has all we need.  It will not change a thing because these records are
        //intended to be used for building histograms.
        GFFRecord gff = new GFFRecord();
        gff.setSeqid(mp.getSubjectID());
        gff.setSource(this.mappedPositionType);
        gff.setType("region");
        gff.setStart(mp.getStart());
        gff.setEnd(mp.getEnd());
        gff.setScore(mp.getWeight());
        gff.setStrand(mp.getStrand());
        gff.setPhase(".");
        gff.setAttributes(".");
        return gff;
    }

    public Record getMappedPosition(String type){
        return getMappedRecord(type, "");
    }

    public Record getMappedRecord(String type, String data){
        if(type.equalsIgnoreCase("biofilter.records.BowTieRecord")){
            BowTieRecord btr = new BowTieRecord();
            btr.set(data);
            return btr;
        }
        if(type.equalsIgnoreCase("biofilter.records.BlastTabRecord")){
            BlastTabRecord btr = new BlastTabRecord();
            btr.set(data);
            return btr;
        }
        if(type.equalsIgnoreCase("biofilter.records.Mapper454Record")){
            Mapper454Record m454 = new Mapper454Record();
            m454.set(data);
            return m454;
        }
        if(type.equalsIgnoreCase("biofilter.records.GFFRecord")){
            GFFRecord gff = new GFFRecord();
            gff.set(data);
            return gff;
        }
        return null;
    }

    public Record getMappedPosition(){
        return getMappedPosition(this.mappedPositionType);
    }

    private String mappedPositionType = null;

    public String getMappedPositionType() {
        return mappedPositionType;
    }

    public void setMappedPositionType(String mappedPositionType) {
        this.mappedPositionType = mappedPositionType;
    }


}
